package org.unicom.quartz.test.boot;

import org.quartz.*;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Date;

@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class QuartzJob extends QuartzJobBean {

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        try {
            Thread.sleep(2000);
            System.out.println(context.getScheduler().getSchedulerInstanceId());
            System.out.println("job_instance_id" + System.identityHashCode(context.getJobInstance().hashCode()));
            System.out.println(System.identityHashCode(context.getJobInstance().hashCode()) + "开始挂起任务");

            System.out.println("task-name = "+ context.getJobDetail().getKey().getName());
            System.out.println("execute time : " + new Date());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (SchedulerException e) {
            throw new RuntimeException(e);
        }
    }

}
